using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Member_Shop_PaymentType : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected GridView GridView1;
	protected TextBox TxtPayName;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected DropDownList DropPayAttribute;
	protected DropDownList ShopOnlinePaytype;
	protected TextBox OnlinePayEmail;
	protected TextBox Account;
	protected TextBox Md5Code;
	protected TextBox OnlinePayFlag;
	protected HtmlGenericControl online_payTypeSelect;
	protected DropDownList outLinePayType;
	protected HtmlGenericControl outLinePayTypeDiv;
	protected UpdatePanel UpdatePanel1;
	protected HiddenField payTypeID;
	protected TextBox TxtDisCount;
	protected RequiredFieldValidator Rq2;
	protected RangeValidator Ra1;
	protected CheckBox ChDisable;
	protected TextBox TxtIntro;
	protected TextBox UserSavePass;
	protected RequiredFieldValidator Rq4;
	protected Label err_tips;
	protected Button OnLinePaySubmit;
	protected Button btnEdit;
	protected int UserID = 0;
	protected string m_selectPayType = "0";
	private Shop_PayType _shop_payType = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_PayType shop_payType
	{
		get
		{
			Shop_PayType shop_payType;
			if (this._shop_payType == null)
			{
				this._shop_payType = new Shop_PayType(this.conn);
				shop_payType = this._shop_payType;
			}
			else
			{
				shop_payType = this._shop_payType;
			}
			return shop_payType;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		if (Fetch.Get("Action") == "delete" && Fetch.GetID("pid") > 0)
		{
			this.DeletePayType();
		}
		else
		{
			if (!base.IsPostBack)
			{
				this.BindPage();
			}
		}
		if (!base.IsPostBack)
		{
			this.DropPayAttribute.Attributes.Add("onchange", "return ChangePayMode();");
			if (this.DropPayAttribute.SelectedValue == "0")
			{
				this.online_payTypeSelect.Style["display"] = "block";
				this.outLinePayTypeDiv.Style["display"] = "none";
			}
			else
			{
				if (this.DropPayAttribute.SelectedValue == "2")
				{
					this.online_payTypeSelect.Style["display"] = "none";
					this.outLinePayTypeDiv.Style["display"] = "block";
				}
			}
			if (Fetch.Get("action") == "edit")
			{
				if (Fetch.GetID("Typeid") > 0)
				{
					int iD = Fetch.GetID("Typeid");
					this.btnEdit.Visible = true;
					this.OnLinePaySubmit.Visible = false;
					this.payTypeID.Value = iD.ToString();
					DataTable typeByID = this.shop_payType.GetTypeByID(iD);
					foreach (DataRow dataRow in typeByID.Rows)
					{
						int num = int.Parse(dataRow["PayType"].ToString());
						if (num == 2)
						{
							this.DropPayAttribute.SelectedValue = "2";
							this.online_payTypeSelect.Style["display"] = "none";
							this.outLinePayTypeDiv.Style["display"] = "block";
							if (dataRow["OutlinePay"] != DBNull.Value)
							{
								string b = dataRow["OutlinePay"].ToString();
								for (int i = 0; i < this.outLinePayType.Items.Count; i++)
								{
									if (this.outLinePayType.Items[i].Value == b)
									{
										this.outLinePayType.Items[i].Selected = true;
									}
								}
							}
						}
						else
						{
							this.DropPayAttribute.SelectedValue = "0";
							this.online_payTypeSelect.Style["display"] = "block";
							this.outLinePayTypeDiv.Style["display"] = "none";
							if (dataRow["OnlinePay"] != DBNull.Value)
							{
								string b2 = dataRow["OnlinePay"].ToString();
								for (int i = 0; i < this.ShopOnlinePaytype.Items.Count; i++)
								{
									if (this.ShopOnlinePaytype.Items[i].Value == b2)
									{
										this.ShopOnlinePaytype.Items[i].Selected = true;
									}
								}
							}
							this.OnlinePayEmail.Text = dataRow["payAccount"].ToString();
							this.Account.Text = dataRow["BussinessCount"].ToString();
							this.OnlinePayFlag.Text = dataRow["payTypeFlag"].ToString();
						}
						this.TxtPayName.Text = dataRow["TypeName"].ToString();
						this.TxtDisCount.Text = dataRow["Discount"].ToString();
						if (bool.Parse(dataRow["IsDisabled"].ToString()))
						{
							this.ChDisable.Checked = true;
						}
						else
						{
							this.ChDisable.Checked = false;
						}
						this.TxtIntro.Text = dataRow["Intro"].ToString();
					}
				}
			}
		}
	}
	protected void BindPage()
	{
		Shop_PayType shop_PayType = new Shop_PayType(this.conn);
		DataTable payTypeByUserID = shop_PayType.GetPayTypeByUserID(this.UserID);
		if (payTypeByUserID.Rows.Count > 0)
		{
			this.GridView1.DataSource = payTypeByUserID;
			this.GridView1.DataBind();
		}
		if (base.shopconfig["OnlinePay"].ToString() == "1")
		{
			this.DropPayAttribute.Items[0].Enabled = true;
		}
		else
		{
			this.DropPayAttribute.Items[0].Selected = false;
		}
		if (base.shopconfig["VoidPay"].ToString() == "1")
		{
			this.DropPayAttribute.Items[1].Enabled = false;
			if (!this.DropPayAttribute.Items[0].Selected)
			{
				this.DropPayAttribute.Items[1].Selected = false;
			}
			else
			{
				this.DropPayAttribute.Items[0].Selected = false;
			}
		}
		if (base.shopconfig["LeavePay"].ToString() == "1")
		{
			this.DropPayAttribute.Items[2].Enabled = true;
		}
		this.m_selectPayType = this.DropPayAttribute.SelectedValue;
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			if (gridViewRow.RowType == DataControlRowType.DataRow)
			{
				gridViewRow.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
				gridViewRow.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
			}
		}
	}
	protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		int typeID = int.Parse(this.GridView1.Rows[e.RowIndex].Cells[0].Text);
		if (this.shop_payType.DeleteType(typeID, base.user.UserID))
		{
			this.WriteSuccessMsg("", Language.GetMemberMsg("Common/DeleteSuccess", new string[0]), "Shop_PaymentType.aspx");
		}
	}
	protected void DropPayAttribute_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (this.DropPayAttribute.SelectedValue == "0")
		{
			this.online_payTypeSelect.Style["display"] = "block";
			this.outLinePayTypeDiv.Style["display"] = "none";
		}
		else
		{
			if (this.DropPayAttribute.SelectedValue == "2")
			{
				this.online_payTypeSelect.Style["display"] = "none";
				this.outLinePayTypeDiv.Style["display"] = "block";
			}
		}
	}
	protected void SetDefault_OnCommand(object sender, CommandEventArgs e)
	{
		Shop_PayType shop_PayType = new Shop_PayType(this.conn);
		shop_PayType.SetPayTypeAsDefault(base.user.UserID, int.Parse(e.CommandArgument.ToString()));
		this.BindPage();
	}
	protected void DeletePayType()
	{
		int iD = Fetch.GetID("pid");
		if (iD > 0)
		{
			Shop_PayType shop_PayType = new Shop_PayType(this.conn);
			if (shop_PayType.DeleteType(iD, this.UserID))
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/DeleteSuccess", new string[0]), "Shop_PaymentType.aspx");
			}
			else
			{
				this.WriteErrMsg("", Language.Get("Common/Fail"), "");
			}
		}
		else
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/ParamErr", new string[]
			{
				""
			}), "");
		}
	}
	protected void OnLinePaySubmit_Click(object sender, EventArgs e)
	{
		if (!Text.CheckMd5Text(this.Md5(this.UserSavePass.Text), base.user.Password))
		{
			this.WriteErrMsg("", Language.GetMemberMsg("PayType/PasswordErr", new string[0]), "");
		}
		int num = Text.ToInt32(base.user.GetGroupPower("maxpaytype"));
		if (num > 0)
		{
			Shop_PayType shop_PayType = new Shop_PayType(this.conn);
			if (num <= shop_PayType.CountUserPayTypeNum(base.user.UserID))
			{
				this.WriteErrMsg("", Language.GetMemberMsg("PayType/PayTypeNumErr", new string[]
				{
					num.ToString()
				}), "");
			}
		}
		Shop_PayType shop_PayType2 = new Shop_PayType(this.conn);
		string text = this.TxtPayName.Text.Replace("'", "").Replace("\"", "");
		string onlinePay = "";
		string text2 = "";
		string bussinesMD5Key = "";
		string text3 = "";
		string payTypeFlag = "";
		bool isDefault = false;
		string outlinePay = "";
		if (this.DropPayAttribute.SelectedValue == "0")
		{
			onlinePay = this.ShopOnlinePaytype.SelectedValue;
			text2 = this.OnlinePayEmail.Text;
			text3 = this.Account.Text;
			payTypeFlag = this.OnlinePayFlag.Text;
			bussinesMD5Key = this.Md5Code.Text;
		}
		else
		{
			if (this.DropPayAttribute.SelectedValue == "2")
			{
				outlinePay = this.outLinePayType.SelectedValue;
			}
		}
		decimal discount = int.Parse(this.TxtDisCount.Text);
		int userID = base.user.UserID;
		bool @checked = this.ChDisable.Checked;
		string text4 = this.TxtIntro.Text;
		int isOpen = 1;
		if (@checked)
		{
			isOpen = 0;
		}
		int num2 = int.Parse(this.DropPayAttribute.SelectedValue);
		string sysStr = "alipay";
		int num3 = num2;
		if (num3 == 0)
		{
			sysStr = "alipay";
		}
		OnlinePaySeting onlinePaySeting = new OnlinePaySeting(this.conn);
		DataTable paySetingByUserID = onlinePaySeting.GetPaySetingByUserID(userID);
		if (shop_PayType2.AddPayType(onlinePay, discount, text, userID, text2, bussinesMD5Key, text3, payTypeFlag, isDefault, @checked, text4, num2, outlinePay))
		{
			if (paySetingByUserID.Rows.Count <= 0 || paySetingByUserID == null || paySetingByUserID.Rows == null)
			{
				if (onlinePaySeting.AddByUserID(text, text3, this.Md5Code.Text, text2, isOpen, sysStr, userID))
				{
					if (onlinePaySeting.updateUserID(userID))
					{
						this.WriteSuccessMsg("", Language.GetMemberMsg("Common/AddSuccess", new string[0]), "Shop_PaymentType.aspx");
					}
					else
					{
						this.WriteErrMsg("", Language.GetMemberMsg("Common/AddFail", new string[]
						{
							"更新userID的时候。"
						}), "");
					}
				}
				else
				{
					this.WriteErrMsg("", Language.GetMemberMsg("Common/AddFail", new string[]
					{
						"添加签约用户信息的时候。"
					}), "");
				}
			}
			else
			{
				if (onlinePaySeting.updateByUserID(userID, text, text3, this.Md5Code.Text, text2))
				{
					this.WriteSuccessMsg("", Language.GetMemberMsg("Common/AddSuccess", new string[0]), "Shop_PaymentType.aspx");
				}
				else
				{
					this.WriteErrMsg("", Language.GetMemberMsg("Common/AddFail", new string[]
					{
						"更新签约信息的时候。"
					}), "");
				}
			}
		}
		else
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/AddFail", new string[]
			{
				""
			}), "");
		}
	}
	protected void btnEdit_Click(object sender, EventArgs e)
	{
		if (!Text.CheckMd5Text(this.UserSavePass.Text, base.user.Password))
		{
			this.WriteErrMsg("", Language.GetMemberMsg("PayType/PasswordErr", new string[0]), "");
		}
		string typeName = this.TxtPayName.Text.Replace("'", "").Replace("\"", "");
		string onlinePay = "";
		string payAccount = "";
		string bussinesMD5Key = "";
		string bussinessCount = "";
		string onlinePayFlag = "";
		string outlinePay = "";
		int payType = int.Parse(this.DropPayAttribute.SelectedValue);
		if (this.DropPayAttribute.SelectedValue == "0")
		{
			onlinePay = this.ShopOnlinePaytype.SelectedValue;
			payAccount = this.OnlinePayEmail.Text;
			bussinessCount = this.Account.Text;
			onlinePayFlag = this.OnlinePayFlag.Text;
			DataTable typeByID = this.shop_payType.GetTypeByID(int.Parse(this.payTypeID.Value));
			if (this.Md5Code.Text == "")
			{
				bussinesMD5Key = typeByID.Rows[0]["BussinesMD5Key"].ToString();
			}
			else
			{
				bussinesMD5Key = this.Md5Code.Text;
			}
		}
		else
		{
			if (this.DropPayAttribute.SelectedValue == "2")
			{
				outlinePay = this.outLinePayType.SelectedValue;
			}
		}
		int userID = base.user.UserID;
		decimal discount = int.Parse(this.TxtDisCount.Text);
		bool @checked = this.ChDisable.Checked;
		string text = this.TxtIntro.Text;
		Shop_PayType shop_PayType = new Shop_PayType(this.conn);
		if (shop_PayType.UpdatePayType(onlinePay, discount, typeName, userID, payAccount, bussinesMD5Key, bussinessCount, onlinePayFlag, @checked, text, payType, int.Parse(this.payTypeID.Value), outlinePay))
		{
			if (Fetch.Get("gourl") != string.Empty)
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/EditSuccess", new string[0]), Fetch.Get("gourl"));
			}
			else
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/EditSuccess", new string[0]), "Shop_PaymentType.aspx");
			}
		}
		else
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/EditFail", new string[]
			{
				""
			}), "");
		}
	}
}
